<?php
/**
 * 广告添加
 *
 * @version        $Id: ad_add.php 1 8:26 2010年7月12日Z tianya $
 * @package        DedeCMS.Administrator
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
 
require(dirname(__FILE__)."/config.php");
require_once DEDEINC."/typelink.class.php";
require_once(DEDEADMIN.'/inc/inc_web.class.php');
require_once(DEDEADMIN.'/inc/inc_catalog_options.php');
if(empty($dopost)) $dopost = "";

if($dopost=="save")
{
	$path="../uploads/web/"; //上传路径 
	if(!is_dir($path))
	{
	//检查是否有该文件夹，如果没有就创建，并给予最高权限
		mkdir($path, 0777);
	}//END IF
	//允许上传的文件格式
	$tp = array("image/gif","image/pjpeg","image/png","image/jpeg");
	
	//检查上传文件是否在允许上传的类型
	if($_FILES["big_img"]["name"] && !in_array($_FILES["big_img"]["type"],$tp) )
	{
		ShowMsg("大图文件格式不对!","web_add.php");
		exit();
	}//END IF
	if($_FILES["small_img"]["name"] && !in_array($_FILES["small_img"]["type"],$tp)){
		ShowMsg("小图文件格式不对!","web_add.php");
		exit();
	}
	$flag1 = false;
	$flag2 = false;
	if($_FILES["big_img"]["name"])
	{
		$file1=pathinfo($_FILES["big_img"]["name"]);
		$ext = $file1['extension'];
		$big_img = $path.'big_'.date('Ymd-His', time()).rand(10000,100000).'.'.$ext;
		$flag1=TRUE;
	}//END IF
	if($_FILES["small_img"]["name"])
	{
		$file1=pathinfo($_FILES["small_img"]["name"]);
		$ext = $file1['extension'];
		$small_img = $path.'small_'.date('Ymd-His', time()).rand(10000,100000).'.'.$ext;
		$flag2=TRUE;
	}//END IF
	if($flag1) {
		move_uploaded_file($_FILES["big_img"]["tmp_name"], $big_img);
		$big_img = str_replace('..', '', $big_img);
	}
	if($flag2){
		move_uploaded_file($_FILES["small_img"]["tmp_name"], $small_img);
		$small_img = str_replace('..', '', $small_img);
	}
	if (!$arctype_id){
		$arctype_id=0;
	}
    $query = "INSERT INTO #@__web(link,title,remark,big_img,small_img,sort,arctype_id,position,add_time)
     VALUES('$link','$title','$remark','$big_img','$small_img','$sort','$arctype_id','$position','".date('Y-m-d H:i:s',time())."')";
     $dsql->ExecuteNoneQuery($query);
    ShowMsg("成功增加一个广告！","web_add.php");
    exit();
}
$channelid = empty($channelid) ? 0 : intval($channelid);
$cid = empty($cid) ? 0 : intval($cid);
include DedeInclude('templets/web_add.htm');